package com.jiaxu.fileexplorer.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jiaxu.fileexplorer.R;
import com.jiaxu.fileexplorer.utils.Globals;

import java.util.List;
import java.util.Map;

/**
 * Created by jiaxu on 2016-4-21.
 */
public class Myadapter extends BaseAdapter {
    private Context context;
    private List<Map<String,Object>> values;
    public Myadapter(Context context,List<Map<String,Object>> values){
        this.context = context;
        this.values = values;
    }

    @Override
    public int getCount() {
        return values.size();
    }

    @Override
    public Object getItem(int i) {
        return values.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if(view == null){
            view = LayoutInflater.from(context).inflate(R.layout.item_line,null);
            view.setLayoutParams(new AbsListView.LayoutParams(view.getLayoutParams().MATCH_PARENT, Globals.SCREEN_HEIGHT/11));
        }

        TextView fileimg = (TextView) view.findViewById(R.id.img_view);
        TextView filename = (TextView) view.findViewById(R.id.name_view);

        Map<String,Object> map = values.get(i);
        filename.setText(map.get("filename").toString());

        if(null==Globals.img.get(map.get("extname"))){
            fileimg.setBackgroundResource(R.drawable.otherfile);
        }else{
            fileimg.setBackgroundResource((int)Globals.img.get(map.get("extname")));
        }
        fileimg.getLayoutParams().height = Globals.SCREEN_HEIGHT/11;
        return view;
    }
}
